// pages/bar/bar.js
var timer
var isTimer=false
Page({

  /**
   * 页面的初始数据
   */
  data: {
    randMode:"随机",
    isRand:true,
    percent:[8,16,25,34,42,50,58,66,75,86,92,100],
    color:["#f00","#f90","#ff0","#9f0","#0f0","#0f9","#0ff","#09f","#00f","#90f","#f0f","#f09"]

  },
  p:[8,16,25,34,42,50,58,66,75,86,92,100],
  c:["#f00","#f90","#ff0","#9f0","#0f0","#0f9","#0ff","#09f","#00f","#90f","#f0f","#f09"],


  randColor:function(){
    var r=Math.floor(Math.random()*255)
    var g=Math.floor(Math.random()*255)
    var b=Math.floor(Math.random()*255)
    var str="rgb("+r+","+g+","+b+")"
    return str
  },
  setRand:function(e){
    if(e.detail.value){
      this.setData({isRandL:true})
      this.setData({randMode:"随机"})
    }else{
      this.setData({isRandL:false})
      this.setData({randMode:"依次"})
    }
  },


  randWave:function(){
    for(var i=0;i<12;i++){
      var rnd=Math.floor(Math.random()*101)
      this.p[i]=rnd
      this.c[i]=this.randColor()
    }
    this.setData({percent:this.p})
    this.setData({color:this.c})
  },
  stepWave:function(){
    for(var i=0;i<11;i++){
      this.p[i]=this.p[i+1]
      this.c[i]=this.c[i+1]
    }
    this.p[11]=Math.floor(Math.random()*101)
    this.c[11]=this.randColor()
    this.setData({percent:this.p})
    this.setData({color:this.c})
  },



  manualWave:function(){
    clearTimeout(timer)
    if(this.data.isRand){
      this.randWave()
    }else{
      this.stepWave()
    }
  },
  autoWave:function(){
    clearTimeout(timer)
    if(this.data.isRand){
      this.randWave()
    }else{
      this.stepWave()
    }
    timer=setTimeout(this.autoWave,300)
  },
  resetWave:function(){
    clearTimerout(timer)
    var p=[8,16,25,34,42,50,58,66,75,86,92,100]
    var c=["#f00","#f90","#ff0","#9f0","#0f0","#0f9","#0ff","#09f","#00f","#90f","#f0f","#f09"]
    this.setData({percent:p})
    this.setData({color:c})
    this.p=p
    this.c=c
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})